package com.example.children.Service;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.children.DTO.AttendanceTeacherDTO;
import com.example.children.DTO.BehaviorTeacherDTO;
import com.example.children.FileService.BehaviorInterface;
import com.example.children.Mapper.BehaviorMapper;
import com.example.children.Model.Attendance;
import com.example.children.Model.Behavior;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service   //日常行为
public class BehaviorService extends ServiceImpl<BehaviorMapper, Behavior> implements BehaviorInterface {

    @Autowired
    private BehaviorMapper behaviorMapper;


    //根据查询日常
    public List<Behavior> selectByDateBehaviorId(Behavior behavior) {
        return behaviorMapper.selectByDateSend(behavior);
    }

    public void addBehavior(Behavior behavior) {
        behaviorMapper.insert(behavior);
    }


    //根据id查找
    public List<Behavior> getBehaviorByStudent(String studentId) {
        return behaviorMapper.selectByStudentId(studentId);
    }


    //查询所有日常记录
    public Page<BehaviorTeacherDTO> GetAllBehavior(int pageNo, int pageSize) {
        // 计算分页的偏移量
        int offset = (pageNo - 1) * pageSize;

        // 获取当前页的数据
        List<BehaviorTeacherDTO> records = behaviorMapper.GetAllBehaviorTeacherDTO(offset, pageSize);
        // 获取总记录数
        int total = behaviorMapper.countTotalRecords();
        // 构造并返回分页对象
        Page<BehaviorTeacherDTO> page = new Page<>();
        page.setTotal(total);
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        page.setRecords(records);

        return page;
    }

    //admin
    public List<BehaviorTeacherDTO> AdminselectByDateSend(BehaviorTeacherDTO behaviorTeacherDTO) {
        return behaviorMapper.AdminSelectByDateSend(behaviorTeacherDTO);
    }
}
